package org.example.leetCode;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @author Administrator
 */
public class Combine {
    List<List<Integer>> result = new ArrayList<>();
    LinkedList<Integer> path = new LinkedList<>();
    public List<List<Integer>> combine(int n, int k) {
        combineArray(n,k,1);
        return result;
    }

    private void combineArray(int n, int k, int i) {
        if (path.size()==k){
            result.add(new ArrayList<>(path));
            return;
        }
        for (int j = i;j<n-(k-path.size());j++){
            path.add(j);
            combineArray(n,k,j+1);
            path.removeLast();
        }
    }
}
